CREATE PROCEDURE [dbo].[ReferrerSave]
@Id				UNIQUEIDENTIFIER,
@FirstName		NVARCHAR(50),
@ClinicName		NVARCHAR(50),
@LastName		NVARCHAR(50),
@Email			NVARCHAR(100)
AS

DECLARE	@RowCount AS INT
DECLARE @Error AS INT

UPDATE	Referrer
SET		[FirstName]		= ISNULL(@FirstName, [FirstName]), 
		ClinicName		= ISNULL(@ClinicName, ClinicName), 	
		LastName		= ISNULL(@LastName, LastName),
		Email			= ISNULL(@Email, Email)
WHERE	Id = @Id

SELECT @Error = @@ERROR, @RowCount = @@ROWCOUNT

IF @Error  <> 0
BEGIN
	RAISERROR('ERROR::ReferrerSave:Error in',16,1)
END

IF @RowCount  > 0
BEGIN
	RETURN @RowCount 
END

--	If adding for first time enter all the details including Id
INSERT	INTO Referrer (Id, [FirstName], ClinicName, LastName, Email)
VALUES	(@Id, @FirstName, @ClinicName, @LastName, @Email)

SELECT	@Error = @@ERROR, @RowCount = @@ROWCOUNT

IF @Error  <> 0
BEGIN
	RAISERROR('ERROR::ReferrerNew:Error in',16,1)
END

RETURN @RowCount